import { createRouter, createWebHashHistory } from "vue-router";

const login = () => import("../components/LoginDiv.vue");
const DataShow = () => import("../components/DataShow.vue");
const home = () => import("../components/Home.vue");
const right = () => import("../components/RightDiv.vue");
const AddUser = () => import("../components/AddUser.vue");
const DevList = () => import("../components/DevList.vue");
const LogList = () => import("../components/LogList.vue");
const UpGrade = () => import("../components/UpGrade.vue");
const MainDiv = () => import("../components/MainDiv.vue");
const UserList = () => import("../components/User.vue");
const Health = () => import("../components/Health.vue");
const Power = () => import("../components/Power.vue");
const FindDev = () => import("../components/FindDev.vue");
const Parameter = () => import("../components/Parameter.vue");
const TipList = () => import("../components/TipList.vue");
const AddOTA = () => import("../components/AddOTA.vue");

const routes = [
	// { path: "/", name: "logList", component: LogList },
	{ path: "/", name: "login", component: login },
	{
		path: "/Home",
		name: "home",
		component: home,
		children: [
			{
				path: "RightDiv",
				name: "RightDiv",
				title: "侧滑",
				component: right,
			},
			{
				path: "MainDiv",
				name: "MainDiv",
				title: "主页",
				component: MainDiv,
				children: [
					{
						path: "Parameter",
						name: "Parameter",
						title: "导航",
						component: Parameter,
					},
					{
						path: "DataShow",
						name: "DataShow",
						title: "设备",
						component: DataShow,
					},
					{
						path: "TipList",
						name: "TipList",
						title: "设备",
						component: TipList,
					},
					{
						path: "DataShow",
						name: "DataShow",
						title: "设备",
						component: DataShow,
					},
					{
						path: "DevList",
						name: "DevList",
						title: "设备列表",
						component: DevList,
					},
					{
						path: "AddUser",
						name: "AddUser",
						title: "增加用户",
						component: AddUser,
					},
					{
						path: "UserList",
						name: "UserList",
						title: "用户列表",
						component: UserList,
					},
					{
						path: "FindDev",
						name: "FindDev",
						title: "查询设备",
						component: FindDev,
					},
					{
						path: "UpGrade",
						name: "UpGrade",
						title: "升级固件",
						component: UpGrade,
					},
					{
						path: "Health",
						name: "Health",
						title: "健康报告分析",
						component: Health,
					},
					{
						path: "Power",
						name: "Power",
						title: "功耗",
						component: Power,
					},
					{
						path: "LogList",
						name: "LogList",
						title: "日志列表",
						component: LogList,
					},
					{
						path: "AddOTA",
						name: "AddOTA",
						title: "添加OTA固件",
						component: AddOTA,
					},
				],
			},
			{
				path: "*",
				name: "error",
				component: Error,
			},
		],
	},
];

const router = createRouter({
	history: createWebHashHistory(),
	routes: routes,
});

// 动态修改路由过度动画
router.afterEach((to, from) => {
	const toDepth = to.path.split("/").length;
	const fromDepth = from.path.split("/").length;
	/*     console.log(toDepth)
    console.log(fromDepth)
    console.log(to)
    console.log(from) */
	if (to.path == "/login") {
		to.meta.transitionName = "down";
		from.meta.transitionName = "opt";
	} else if (from.path == "/login") {
		from.meta.transitionName = "down";
		to.meta.transitionName = "up";
	} else {
		to.meta.transitionName =
			toDepth <= fromDepth ? "slide_left" : "slide_right";
	}
});

export default router;
